package com.kkd.kkdapp.adapter;

import java.util.List;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.http.entity.Share;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ShareGridViewAdapter extends BaseAdapter {

	private Context context;
	private List<Share> mList;

	public ShareGridViewAdapter(Context context, List<Share> mList) {
		this.context = context;
		this.mList = mList;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder mViewHolder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.share_gridview_item,
					null);
			mViewHolder = new ViewHolder();
			mViewHolder.share_img = (ImageView) convertView
					.findViewById(R.id.share_img);
			mViewHolder.share_name = (TextView) convertView
					.findViewById(R.id.share_name);
			convertView.setTag(mViewHolder);
		} else {
			mViewHolder = (ViewHolder) convertView.getTag();
		}

		mViewHolder.share_img.setImageResource(mList.get(position)
				.getShareImg());
		mViewHolder.share_name.setText(mList.get(position).getShareName());
		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				mOnItemCliclistener.onPosition(position);
			}
		});
		return convertView;
	}

	class ViewHolder {
		ImageView share_img;
		TextView share_name;
	}

	public void setonItemClickListener(OnItemCliclistener callback) {
		mOnItemCliclistener = callback;
	}

	public OnItemCliclistener mOnItemCliclistener;

	public interface OnItemCliclistener {
		public void onPosition(int id);
	}
}
